package acwing.算法进阶打卡;
/**
 * @author： li
 * @date： 2022-03-13 19:18
 * @version 1.0
 */
/*
* n个数的全排列*/
import java.util.*;
        import java.io.*;
public class 递归实现排列型枚举 {
    static String n;
    static int[] ans = new int[10];
    static boolean[] flag = new boolean[10];
    static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    static void dfs(int n ,int index) throws IOException {
        if(index==n){
            for(int i=0;i<n;i++)
                out.write(ans[i]+" ");
            out.write("\n");
        }
        for(int i=1;i<=n;i++) {
            if(flag[i]){
                ans[index]=i;
                flag[i]=false;
                dfs(n,index+1);
                flag[i]=true;
            }
//            while (i + 1 < n && a[i + 1] == a[i]) i ++ ;
        }
    }
    public static void main(String[] args) throws IOException {
        n = in.readLine();
        Arrays.fill(flag,true);
        dfs(Integer.parseInt(n),0);
        in.close();
        out.flush();
    }
}